#include "StdAfx.h"
#include "AudioOut.h"
#include "jsonreader.h"
#include "SubStructure.h"
#include "BackgroundImage.h"
#include "GameSceneHelp.h"

GameSceneHelp::GameSceneHelp()
{
	HelpImage = new BackgroundImage();
	audio = AudioOut::Instance();
}

GameSceneHelp::~GameSceneHelp()
{
	delete HelpImage;
	
	if(HelpTex != NULL)
	{
		HelpTex->Release();
	}
}

GameSceneState* GameSceneHelp::Instance()
{
	if(_p_this == 0)
	{
		_p_this = new GameSceneHelp();
		_p_this->Init();
	}
	return _p_this;
}

void GameSceneHelp::Init()
{
	TickCount = 0;
	NowState = 0;
	sceneChange = 0;
	changeCount = 0;
	if(D3DXCreateTextureFromFileEx(pd3dDevice, _T("help.png"), 640, 480, 1, NULL,
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0x00000000, NULL, NULL, &HelpTex))
		MessageBox(NULL, _T("help.png is not loaded!!!"), _T("ERROR"), MB_OK);

	RECT temp = {0, 0, 640, 480};
	D3DXVECTOR2 tempxy(0.0, 0.0);
	
	HelpImage->Setrect(temp);
	HelpImage->SetTexture(HelpTex);
	HelpImage->SetInvisible(0xffffffff);
}

void GameSceneHelp::Draw()
{
	HelpImage->Draw();
}

void GameSceneHelp::Reset()
{
	sceneChange = CHANGEIN;
	changeCount = 20;
}

DWORD GameSceneHelp::Update(const KeyInput* input)
{
	TickCount++;
	if(TickCount % 3 || sceneChange != 0)
	{
		if(sceneChange != 0)
		{
			--changeCount;
			if(changeCount == 0 && sceneChange != CHANGEIN)
			{
				Event(PRESSED, PAUSEGAME);
			}
			else if(changeCount == 0)
			{
				sceneChange = 0;
			}
		}
	}
	else
	{
		if(input -> V_Z || input -> V_ESC || input -> V_X)
		{
			sceneChange = CHANGEOTHER;
			changeCount = 30;
		}
	}
	return HELP;
}
